using System;
using System.Collections;
using System.Collections.Generic;
using PEProtocol;
using UnityEngine;
using UnityEngine.UI;

public class UI_Login : WindowRoot
{
    private Button mChangeBtn;
    private InputField mAcctInput;
    private Button mLoginBtn;
    private Text mServerTxt;
    private 
    void Awake()
    {
        mAcctInput = transform.Find("CenterPin/bgFrame/IPT_Acct").GetComponent<InputField>();
        mChangeBtn = transform.Find("CenterPin/BTN_Change").GetComponent<Button>();
        mLoginBtn =  transform.Find("CenterPin/BTN_Login").GetComponent<Button>();
        mServerTxt = mChangeBtn.transform.Find("TXT_Server").GetComponent<Text>();
        
        mChangeBtn.onClick.AddListener(() =>
        {
            
        });
        mLoginBtn.onClick.AddListener(() =>
        {
            mAudioSvc.PlayUIAudio("loginBtnClick");
            if (string.IsNullOrEmpty(mAcctInput.text))
            {
                mUISvc.ShowTips("账号不能为空!");
                return;
            }
            mRoot.AcctSystem.Account = mAcctInput.text;
            NetMsg req = new NetMsg();
            req.CMD = CMD.ReqLogin;
            req.ReqAcctLogin = new ReqAcctLogin();
            req.ReqAcctLogin.Acct = mAcctInput.text;
            req.ReqAcctLogin.PassWord = mAcctInput.text;
            mNetSvc.SendMsg(req, (rsp) =>
            {
                switch (rsp.EID)
                {
                    case ErrorCode.None:
                        mUISvc.ShowTips("登录成功！");
                        break;
                    case ErrorCode.Acct_Online_Login:
                        mUISvc.ShowTips("账号已登录Login");
                        break;
                    case ErrorCode.Acct_Online_Data:
                        mUISvc.ShowTips("账号已登录Data");
                        break;
                    case ErrorCode.Acct_L2D_Offline:
                        mUISvc.ShowTips("当前区服离线，请选择其他大区!");
                        break;
                    default:
                       this.Error($"ErrorCode: {rsp.EID} 未处理");
                        break;
                }
            });


        });

    }

   
}
